package deliciouse.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import deliciouse.dao.FoodDao;
import deliciouse.dao.impl.FoodDaoImpl;
import deliciouse.entity.Food;

@WebServlet("/fooddetails")
public class FoodDetailsServlet extends HttpServlet {

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	int id = 0;
	if (request.getParameter("id") != null && !request.getParameter("id").isEmpty()) {
		id = Integer.valueOf(request.getParameter("id"));
	}
	FoodDao food = new FoodDaoImpl();
	List<Food> flist = food.getAll();
	Food f = food.fetchById(id);
	request.setAttribute("f", f);
	request.setAttribute("flist", flist);
	request.getRequestDispatcher("/fooddetails.jsp").forward(request, response);
}
}
